package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TRecor;
import com.ruoyi.system.service.ITRecorService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 品类品种操作记录 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-05-22
 */
@Controller
@RequestMapping("/system/tRecor")
public class TRecorController extends BaseController
{
    private String prefix = "system/tRecor";
	
	@Autowired
	private ITRecorService tRecorService;
	
	@RequiresPermissions("system:tRecor:view")
	@GetMapping()
	public String tRecor()
	{
	    return prefix + "/tRecor";
	}
	
	/**
	 * 查询品类品种操作记录列表
	 */
	@RequiresPermissions("system:tRecor:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TRecor tRecor)
	{
		startPage();
        List<TRecor> list = tRecorService.selectTRecorList(tRecor);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出品类品种操作记录列表
	 */
	@RequiresPermissions("system:tRecor:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TRecor tRecor)
    {
    	List<TRecor> list = tRecorService.selectTRecorList(tRecor);
        ExcelUtil<TRecor> util = new ExcelUtil<TRecor>(TRecor.class);
        return util.exportExcel(list, "tRecor");
    }
	
	/**
	 * 新增品类品种操作记录
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存品类品种操作记录
	 */
	@RequiresPermissions("system:tRecor:add")
	@Log(title = "品类品种操作记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TRecor tRecor)
	{		
		return toAjax(tRecorService.insertTRecor(tRecor));
	}

	/**
	 * 修改品类品种操作记录
	 */
	@GetMapping("/edit/{userId}")
	public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
	{
		TRecor tRecor = tRecorService.selectTRecorById(userId);
		mmap.put("tRecor", tRecor);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存品类品种操作记录
	 */
	@RequiresPermissions("system:tRecor:edit")
	@Log(title = "品类品种操作记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TRecor tRecor)
	{		
		return toAjax(tRecorService.updateTRecor(tRecor));
	}
	
	/**
	 * 删除品类品种操作记录
	 */
	@RequiresPermissions("system:tRecor:remove")
	@Log(title = "品类品种操作记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tRecorService.deleteTRecorByIds(ids));
	}
	
}
